package zj.boxuegu.administrator.myapplication.Activity;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;


import com.google.gson.Gson;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.ArrayList;

import zj.boxuegu.administrator.myapplication.Fragment.CouserFragment;
import zj.boxuegu.administrator.myapplication.Fragment.ExerciseFragment;
import zj.boxuegu.administrator.myapplication.Fragment.MyFragment;
import zj.boxuegu.administrator.myapplication.R;

public class MainActivity extends AppCompatActivity {
 FragmentManager fragmentManager;
    FragmentTransaction fragmentTransaction;
    TextView textView1,textView2,textView3;
    ImageView imageView1,imageView2,imageView3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
           textView1 = (TextView) findViewById(R.id.m_1);
        textView2 = (TextView) findViewById(R.id.m_2);
        textView3 = (TextView) findViewById(R.id.m_3);
        imageView1 = (ImageView) findViewById(R.id.im_1);
        imageView2 = (ImageView) findViewById(R.id.im_2);
        imageView3 = (ImageView) findViewById(R.id.im_3);
        //textView1.setTextColor(Color.parseColor("0C92FF"));
       // imageView1.setImageResource(R.drawable.main_course_icon_selected);
        fragmentManager=getFragmentManager();
        fragmentTransaction =fragmentManager.beginTransaction();
        fragmentTransaction.add(R.id.fragment,new CouserFragment());
        fragmentTransaction.commit();

    }
    public  void  couser(View view) {

        textView1.setTextColor(Color.parseColor("#0C92FF"));
        textView2.setTextColor(Color.parseColor("#000000"));
        textView3.setTextColor(Color.parseColor("#000000"));
       imageView1.setImageResource(R.drawable.main_course_icon_selected);
        imageView3.setImageResource(R.drawable.main_my_icon);
        imageView2.setImageResource(R.drawable.main_exercises_icon);
        fragmentManager = getFragmentManager();
        fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment, new CouserFragment());
        fragmentTransaction.commit();

    }
    public void but10(View view){
        RequestParams params = new RequestParams("http://1633.applinzi.com/public/?s=App.Course.Getcourse");


        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {


                Gson gson =new  Gson();

                CouserModel couserModel =gson.fromJson(result,CouserModel.class);



//                if(CouserModel.==200){
//                  //  Intent intent =new Intent(LoginActivity.this,MainActivity.class);
//                   // startActivity(intent);
//
//                }else{
//
//                }
                Log.i("MainActivity","onSuccess CouserModel code"+couserModel.code);

            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                Toast.makeText(x.app(), ex.getMessage(), Toast.LENGTH_LONG).show();



            }

            @Override
            public void onCancelled(CancelledException cex) {
                Toast.makeText(x.app(), "cancelled", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onFinished() {

            }
        });
    }







    public  void  exercise(View view){
        textView1.setTextColor(Color.parseColor("#000000"));
        textView2.setTextColor(Color.parseColor("#0C92FF"));
        textView3.setTextColor(Color.parseColor("#000000"));
        imageView1.setImageResource(R.drawable.main_course_icon);
        imageView3.setImageResource(R.drawable.main_my_icon);
        imageView2.setImageResource(R.drawable.main_exercises_icon_selected);
        fragmentManager=getFragmentManager();
        fragmentTransaction =fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment,new ExerciseFragment());
        fragmentTransaction.commit();
    }
    public  void  my(View view){
        textView1.setTextColor(Color.parseColor("#000000"));
        textView2.setTextColor(Color.parseColor("#000000"));
        textView3.setTextColor(Color.parseColor("#0C92FF"));
        imageView1.setImageResource(R.drawable.main_course_icon);
        imageView3.setImageResource(R.drawable.main_my_icon_selected);
        imageView2.setImageResource(R.drawable.main_exercises_icon);
        fragmentManager=getFragmentManager();
        fragmentTransaction =fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment,new MyFragment());
        fragmentTransaction.commit();
    }
}
